package com.uni.controllers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;

import com.uni.controllers.editors.ListEditor;
import com.uni.controllers.validation.GroupValidator;
import com.uni.db.GenericService;
import com.uni.db.*;
import com.uni.domain.*;


@Controller

public class TimetablePerGroup {
	
	@Autowired
    @Qualifier("groupService")
    private GenericService<Group> groupService;
    
	@RequestMapping("/timetable.htm")
    //@RequestMapping(method = RequestMethod.GET)
    public String setupForm(@RequestParam(value="group", required=true) Long id, ModelMap model) {
    	System.out.print("IN");
    	Group group = groupService.get(id);
    	model.addAttribute("group", group.getPrograms());
        return "timetable";
    }

    //@RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@ModelAttribute Group group,
    		BindingResult result, SessionStatus status ,
    		HttpServletRequest request, 
    		@RequestParam(value="students", required=false) String[] users) throws IOException, ServletException {
    	for(Object o : request.getParameterMap().keySet()){
    		System.out.println(o + " => " + request.getParameterMap().get(o));
    	}
        return "redirect:/group/";
    }
}
